import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class listCourses extends HttpServlet {

	public void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String msg = getCourseList();
		out.println("<html>");
		out.println("<head>");
		out.println("<title>List of Courses</title>");
		out.println("</head>");
		out.println("<body bgcolor=#A3D49C>");
		out.println("<img src='http://i56.tinypic.com/fa61kk.png'>");
		out.println("<br />");
		out.println("<br />");
		out.println("<br />");
		out.println("<br />");
		out.println(msg);
		out.println("</body>");
		out.println("</html>");
	}
	
	public void doPost (HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException {
		doGet(request, response);
	}
	
	private String getCourseList(){
		String msg = "";
		ArrayList<Course> courses = CourseIO.getCourses();
		for (Course c : courses){
			msg += c.name + " - ";
			msg += c.coursename + " - ";
			msg += c.timeHour + ":" + c.timeMinute + "<br />";
		}
		return msg;
	}
}